<template>
    <div>
        <div>
            <Form :label-width="100" inline>
                <FormItem label="行政区划" prop="areacode">
                    <area-linkage :areaCode.sync="queryParam.ssca0043" :countyDisable=false :streetDisable=false
                                  :communityDisable=false></area-linkage>
                </FormItem>
                <Form-item label="户主姓名">
                    <Input v-model="queryParam.azcp0003" placeholder="请输入户主姓名"
                           style="width: 200px"></Input>
                </Form-item>
                <Form-item label="证件号码">
                    <Input v-model="queryParam.azcp0001" placeholder="请输入证件号码"
                           style="width: 200px"></Input>
                </Form-item>
                <FormItem label="银行信息是否已完善" :label-width="labelWidth" >
                    <dictSelect :sel_val='queryParam.complete' dictCode="yesorno" :bindData.sync="queryParam.complete"
                                style="width: 150px" clearable/>
                </FormItem>
                <FormItem label="是否代领">
                    <dictSelect :sel_val='queryParam.ssca0082' dictCode="yesorno" :bindData.sync="queryParam.ssca0082"
                                style="width: 150px" clearable/>
                </FormItem>

                <Row class="button_row">
                    <span style="float: right;">
                      <Button type="primary" @click="searchQuery">查询</Button>
                      <Button type="primary" class="button_item_left" @click="searchReset">重置</Button>
                    </span>
                </Row>
            </Form>
        </div>
        <Modal v-model="visible" :title="title" width="800" style="position:relative;">
            <Form ref="formData" :model="formData" :label-width="150" :rules="rules" :disabled="disableSubmit" :key="key">
                <table style="width:100%;">
                    <tr>
                        <td>
                            <FormItem label="户主身份证号码" prop="azcp0001">
                                <Input v-model="formData.azcp0001" style="width: 200px" readonly></Input>
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="户主姓名" prop="azcp0003">
                                <Input v-model="formData.azcp0003" style="width: 200px" readonly></Input>
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="开户银行名称" prop="ssca0009">
                                <dictSelect :sel_val='formData.ssca0009' dictCode="bankcategory"
                                            :bindData.sync="formData.ssca0009" style="width: 200px" clearable/>
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="是否代领" prop="ssca0082">
                                <dictSelect :sel_val='formData.ssca0082' dictCode="yesorno" @changeState="changeSsca0082"
                                            :bindData.sync="formData.ssca0082" style="width: 200px" clearable/>
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="开户人姓名" prop="ssca0010">
                                <Input v-model="formData.ssca0010" style="width: 200px" v-if="inputSsca0010"></Input>

<!--                                <Input v-model="formData.ssca0010" style="width: 200px"></Input>-->
                                <Select style="width:200px" placeholder="开户人姓名" v-model="formData.ssca0010" clearable
                                        v-if="!inputSsca0010" @on-change="changeSsca0010">
                                    <Option v-for="item in familyMember" :value="item.azcp0003" :key="item.azcp0003">{{ item.azcp0003 }}</Option>
                                </Select>

                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="开户人证件号码" prop="ssca0083">
                                <Input v-model="formData.ssca0083" style="width: 200px"
                                       @on-blur="loadExistData()"></Input>
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="银行卡帐号" prop="ssca0011">
                                <Input v-model="formData.ssca0011" style="width: 200px" type="number"></Input>
                            </FormItem>
                        </td>
                        <td>
                            <FormItem label="银行卡帐号确认" prop="ssca0011_check" v-if="!disableSubmit">
                                <Input v-model="formData.ssca0011_check" style="width: 200px" type="number"></Input>
                            </FormItem>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <FormItem label="代领授权要件">
                                <template>
                                    <Upload name="ssca0095"
                                            ref="upload"
                                            action="/api/ac/hdplugin/ossService/uploadBase64"
                                            :max-size=300
                                            :on-exceeded-size="handleMaxSize"
                                            :before-upload="(file) => beforeUpload(file)"
                                            :show-upload-list=false
                                            :accept="acceptImg">
                                        <Button icon="ios-cloud-upload-outline">上传代领授权要件</Button>
                                    </Upload>
                                    <div>
                                        <img :src="temp_photo" style="width: 100%" @click="visible01=true"/>
                                    </div>
                                    <Modal v-model="visible01" title="查看要件" width="700" style="position:relative;">
                                        <img :src='temp_photo'
                                             style=" width: auto; height: auto; max-width: 100%; max-height: 100%;  ">
                                    </Modal>
                                </template>
                            </FormItem>
                        </td>
                    </tr>
                </table>
            </Form>
            <div slot="footer">
                <Button type="text" size="large" @click="visible = false">取消</Button>
                <template v-if="!disableSubmit">
                    <Button type="primary" size="large" @click="handleSubmit('formData')">确定</Button>
                </template>
            </div>
        </Modal>
        <div class="table_div">
            <vxe-table border
                       resizable
                       row-id="id"
                       :row-key="true"
                       show-overflow="tooltip"
                       highlight-hover-row
                       align="center"
                       header-align="center"
                       ref="xTree"
                       :loading="Loading"
                       :data="tableData">
                <vxe-table-column field="ssca0002_name" title="救助类型" align="center" width="150" fixed="left"/>
                <vxe-table-column field="azaa0002" title="属地区划" align="center" width="250" fixed="left"/>
                <vxe-table-column field="azcp0003" title="户主姓名" align="center" width="100" fixed="left"/>
                <vxe-table-column field="azcp0001" title="证件号码" align="center" width="200" />
                <vxe-table-column field="ssca0009_name" title="开户银行名称" align="center" width="150" />
                <vxe-table-column field="ssca0010" title="开户银行账户" align="center" width="120"/>
                <vxe-table-column field="ssca0011" title="银行卡帐号" align="center" width="220"/>
                <vxe-table-column field="ssca0082_name" title="是否代领" align="center" width="100"/>
                <vxe-table-column field="ssca0083" title="代领人/开户人证件号码" align="center" width="200"/>
                <vxe-table-column field="bpm_status_name" title="数据状态" align="center" width="120"/>
                <vxe-table-column field="" title="操作" min-width="140" fixed="right">
                    <template v-slot="{ row }">
                        <Button type="warning" size="small" style="margin-right: 5px" @click="handleEdit(row)">编辑</Button>
                        <Button type="success" size="small" style="margin-right: 5px" @click="handleDetail(row)">详情</Button>
                    </template>
                </vxe-table-column>
            </vxe-table>
            <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                  @on-change="handleTableChange" :current="pageNo"></Page>
        </div>
    </div>
</template>

<script>
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'
    import dictSelect from '@/components/dictSelect/dictSelect.vue'
    import {IdentityCodeValid} from '@/plugins/idcardValid.js'
    import DateFormat from '@/plugins/format.js'
    import {getSign, createUpLoadFiles, compressImg} from '@/api/common'

    export default {
        mixins: [CommonMixin],
        components: {
            dictSelect,
        },
        data() {
            return {
                labelWidth: 150,
                acceptImg: ".png,.jpg,.jpeg",
                visible01: false,
                key:'',
                rules: {
                    ssca0009: [
                        {required: true, message: '请选择"开户银行名称"', trigger: 'blur'}
                    ],
                    ssca0082: [
                        {required: true, message: '请选择"是否代领"', trigger: 'blur'}
                    ],
                    ssca0010: [
                        {required: true, message: '请选择"开户人姓名"', trigger: 'blur'}
                    ],
                    ssca0083: [
                        {required: true, message: '请输入"开户人证件号码"', trigger: 'blur'}
                    ],
                    ssca0011: [
                        {required: true, message: '请输入"银行卡帐号"', trigger: 'blur'}
                    ],
                    ssca0011_check: [
                        {required: true, message: '请输入"银行卡帐号确认"', trigger: 'blur'}
                    ],
                },
                fieldsToValidate: ["ssca0009", "ssca0082", "ssca0010", "ssca0083", "ssca0011", "ssca0011_check"],
                disableSubmit: false,
                temp_photo: '',
                upPicData: {},
                searchInfo: "",
                sq_disabled: false,
                jd_disabled: false,
                xq_disabled: false,
                tableData: [],
                Loading: false,
                url: {
                    list: "/api/ac/subsistence/ss00016Service/getPageList"
                },
                formData: {
                  azcp0001:null,
                  azcp0003:null,
                  ssca0009:null,
                  ssca0082:null,
                  ssca0010:'',
                  ssca0083:null,
                  ssca0011:null

                },
                processData: {},
                familyMember: [],
                inputSsca0010: true,
                queryParam: {},
                visible: false,
                dataCount: 0,
                pageSize: 10,
                modal: false,
                title: ""
            }
        },
        methods: {
            loadImg(response, file, name, id) {
                if (response.errcode == 0) {
                    this.formData.ssca0095 = response.data;
                    this.temp_photo = response.data;
                } else {
                    this.$Message.error('上传失败！')
                }
                this.Loading = false;
            },
            handleMaxSize() {
                this.$Message.error("文件过大, 请将文件控制在300KB以下再上传")
            },
            handleDetail(row) {
                let that = this;
                that.key=that.uuid();
                that.familyMember = null
                that.title = "详情";
                that.disableSubmit = true;
                // 查询该户所有家庭成员(保障/非保障, 不包含赡扶养人)
                postAction("/api/ac/subsistence/ss00016Service/findMember", row).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.familyMember = res.data.data;
                        this.Loading = false;
                        let record = row;
                        if (record.id) {
                            that.visible = true
                            that.formData={};
                            that.formData = Object.assign({}, record);
                            that.temp_photo = that.formData.ssca0095;
                            if (that.formData.ssca0082 === '1') {
                                that.inputSsca0010 = true
                            } else {
                                that.inputSsca0010 = false
                            }
                            that.ssca0011Check = false;
                        } else {
                            that.visible = false
                        }
                    }
                }).finally(() => {
                });
            },
            handleEdit(row) {
                let that = this;
                that.key=that.uuid();
                that.disableSubmit = false;
                if (row.bpm_status != '100') {
                    this.$Message.error("业务正在办理中, 不允许修改银行账户信息");
                    return;
                }
                that.title = "银行账户信息编辑";
                that.Loading = true;

                // 删除12及17数据
                postAction("/api/ac/subsistence/ss00016Service/delete12And17", row).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                        this.Loading = false;
                        return;
                    } else {
                    }
                }).finally(() => {
                });

                // 查询该户所有家庭成员(保障/非保障, 不包含赡扶养人)
                postAction("/api/ac/subsistence/ss00016Service/findMember", row).then((res) => {
                    if (res.data.errcode != 0) {
                        this.$Message.error(res.data.errmsg);
                    } else {
                        that.familyMember = res.data.data;
                        this.Loading = false;
                    }
                }).finally(() => {
                });
                let record = row;
                if (record.id) {
                    that.visible = true
                    that.formData = Object.assign({}, record);
                    that.changeSsca0010()
                    if (that.formData.ssca0082 === '1') {
                        that.inputSsca0010 = true;
                    } else {
                        that.inputSsca0010 = false;
                    }
                    that.temp_photo = that.formData.ssca0095
                } else {
                    that.visible = false
                }
            },
            handleSubmit(name) {
                let that = this;
                this.temp_photo = "";
                let validate = true;
                let err_msg = [];
                for (let item of that.fieldsToValidate) {
                    that.$refs[name].validateField(item, (error) => {
                        if (error) {
                            validate = false;
                            err_msg.push(that.rules[item][0].message);
                        }
                    })
                }
                let ssca0011 = that.formData.ssca0011;
                let ssca0011_check = that.formData.ssca0011_check;
                if (validate) {
                    // 验证银行卡号是否一致
                    if (ssca0011 != ssca0011_check) {
                        this.$Message.error("两次输入的银行卡号不一致");
                        return;
                    }
                    let that = this;
                    if (that.formData.ssca0082 == "1") {
                        if (that.formData.ssca0095 == "" || that.formData.ssca0095 == undefined) {
                            that.$Message.error("请上传代领授权要件");
                            return;
                        }
                    }
                    that.Loading = true;
                    that.visible = false;
                    let url = "/api/ac/subsistence/ss00016Service/updateData";
                    postAction(url, this.formData).then((res) => {
                        if (res.data.errcode != 0) {
                            this.$Message.error(res.data.errmsg);
                        } else {
                            this.modalFormOk();
                            this.visible = false;
                        }
                    }).finally(() => {
                        that.Loading = false;
                    });
                } else {
                    that.$Message.error(err_msg[0]);
                    return;
                }
            },
            loadExistData() { //输入身份证号码时载入数据
                let that = this
                let azcp0001 = that.formData.ssca0083
                if (azcp0001 != '' && azcp0001 != undefined){
                    azcp0001 = azcp0001.toUpperCase()
                    that.formData.ssca0083 = azcp0001
                    if (!IdentityCodeValid(azcp0001)) {
                        that.$Message.error('申请人身份证号码格式不合法')
                        that.formData.ssca0083 = null
                        return
                    }
                }
            },
            changeSsca0082() {
                let that = this;
                if (that.formData.ssca0082 === '1') {
                    that.formData.ssca0010 = null;
                    that.formData.ssca0083 = null;
                    that.inputSsca0010 = true;
                    that.rules.ssca0010 = {required: true, message: '请输入"开户人姓名"', trigger: 'blur'}
                } else if (that.formData.ssca0082 === '0') {
                    that.formData.ssca0010 = that.formData.azcp0003;
                    that.formData.ssca0083 = that.formData.azcp0001;
                    that.inputSsca0010 = false;
                    that.rules.ssca0010 = {required: true, message: '请选择"开户人姓名"', trigger: 'blur'}
                } else {
                    that.formData.ssca0010 = null;
                    that.formData.ssca0083 = null;
                }
            },
            changeSsca0010() {
                let that = this;
                for (let item in that.familyMember) {
                    if (that.familyMember[item].azcp0003 == that.formData.ssca0010) {
                        that.formData.ssca0083 = that.familyMember[item].azcp0001;
                    }
                }
            },
        },
        created() {
            this.loadData();
        },
    }
</script>
<style scoped>
    /*.paging {*/
    /*    float: right;*/
    /*    margin-top: 10px;*/
    /*}*/

    /*/deep/ .ivu-upload-list {*/
    /*    display: none;*/
    /*}*/
    /deep/ .ivu-form-item-error-tip {
        display: none;
    }

    .itemStyle {
        width: 180px
    }

    .head-img1 {
        height: 200px;
        width: 250px;
        margin-top: 15px;
    }

    .head-img {
        height: 200px;
        width: 250px;
    }

    .imgBackColor {
        background-color: WhiteSmoke;
        height: 250px;
    }

    .positiveTDiv {
        height: 240px;
        width: 75px;
        line-height: 240px;
        background-color: #7CCD7C;
        margin-bottom: 10px;
        color: white;
        font-size: 14px;
        font-weight: 700;
    }
</style>
